<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../res/layui/css/layui.css">
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 0;
        }
        .container {
            max-width: 1200px;
            margin: 20px auto;
            padding: 20px;
            background-color: #fff;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }
        .blog-item {
            margin-bottom: 20px;
            padding: 20px;
            border-bottom: 1px solid #ddd;
        }
        .blog-title {
            font-size: 1.5em;
            margin-bottom: 10px;
            color: #333;
        }
        .blog-content {
            width: 100%;
            height: 150px;
            border: 1px solid #ddd;
            padding: 10px;
            box-sizing: border-box;
            overflow: hidden;
            white-space: normal;
            word-wrap: break-word;
        }
        .blog-item img {
            width: 100%;
            height: 100%;
            object-fit: cover;
            box-shadow: 0 2px 6px gray;
            margin-top: 10px;
        }
    </style>
</head>
<body>
<div class="layui-fluid container">
    <div class="layui-card">
        <div class="layui-card-header">新闻列表</div>
        <div class="layui-card-body">
            <div id="blogslist" class="blog-list"></div>
        </div>
    </div>
</div>
<script src="../res/js/config.js"></script>
<script src="../res/layui/layui.js"></script>
<script>
    layui.use(['jquery', 'layer'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;

        function renderBlogs(data) {
            var container = $('#blogslist');
            container.empty();
            data.forEach(function(blog) {
                var blogItem = `
                    <div class="blog-item">
                        <div class="blog-title">${blog.blogname}</div>
                        <div class="blog-content">${blog.blogtest}</div>
                        <img src="${blog.phoneurl}" alt="Blog Image">
                    </div>
                `;
                container.append(blogItem);
            });
        }

        $.ajax({
            url: 'http://localhost:80/blogs/list',
            type: 'GET',
            data: {
                page: 1,
                limit: 10
            },
            success: function(res) {
                if (res.code === 0) {
                    renderBlogs(res.data);
                } else {
                    layer.msg('加载数据失败');
                }
            },
            error: function() {
                layer.msg('请求出错');
            }
        });
    });
</script>
</body>
</html>
